package com.smartfast4j.common.controller;

import com.smartfast4j.sys.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by gacl on 2017/8/29.
 */
@Controller
@RequestMapping("/view")
public class ViewController {

    @Autowired
    private IUserService userService;

    @RequestMapping(value = "/beetl/index", method = RequestMethod.GET)
    public ModelAndView beetlIndex() {
        /**
         * 这里要注意的是，如果Controller中返回视图加了后缀html或者btl，在配置中就不要加入suffix配置，否则会找不到页面。
         */
        //ModelAndView modelAndView = new ModelAndView("/beetlIndex.html");
        ModelAndView modelAndView = new ModelAndView("/beetlIndex");
        modelAndView.addObject("userList", userService.selectList(null));
        return modelAndView;//返回/WEB-INF/views/beetl/beetlIndex.html视图
    }

    @RequestMapping(value = "/beetl/demo", method = RequestMethod.GET)
    public ModelAndView demo() {
        /**
         * 这里要注意的是，如果Controller中返回视图加了后缀html或者btl，在配置中就不要加入suffix配置，否则会找不到页面。
         */
        /*ModelAndView modelAndView = new ModelAndView("/demo.html");*/
        ModelAndView modelAndView = new ModelAndView("/demo");
        modelAndView.addObject("users", getMockerUsers());
        return modelAndView;//返回/WEB-INF/views/beetl/demo.html视图
    }

    @RequestMapping(value = "/jsp/index", method = RequestMethod.GET)
    public ModelAndView jspIndex() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("jspIndex");
        modelAndView.addObject("userList", userService.selectList(null));
        return modelAndView;//返回/WEB-INF/views/jsp/jspIndex.jsp视图
    }


    @RequestMapping(value = "/ftl/index", method = RequestMethod.GET)
    public ModelAndView ftlIndex() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("ftlIndex");
        modelAndView.addObject("userList", userService.selectList(null));
        return modelAndView;//返回/WEB-INF/views/ftl/ftlIndex.ftl视图
    }

    private Map getMockerUsers() {
        Map<String,Object> map = new HashMap<>();
        map.put("id", 1);
        map.put("name", "曹操");
        map.put("description", "一名枭雄");
        return map;
    }
}
